//
//  CameraBaseView.m
//  callmed
//
//  Created by  FredLing on 2019/9/16.
//  Copyright © 2019 xx. All rights reserved.
//

#import "CameraBaseView.h"
#import "UIView+YLView.h"

@interface CameraBaseView()
@property (nonatomic, strong)UIView *mView;//遮罩
@property (nonatomic, strong)UILabel *tipLabel;//提示语
@end
@implementation CameraBaseView
#define kWidth   [UIScreen mainScreen].bounds.size.width
#define kHeight  [UIScreen mainScreen].bounds.size.height
#define kScaleX  [UIScreen mainScreen].bounds.size.width / 375.f
#define kScaleY  [UIScreen mainScreen].bounds.size.height / 667.f
#define kLineColor [UIColor colorWithRed:41/255. green:130/255. blue:254/255. alpha:1.]

- (void)drawRect:(CGRect)rect {
    
    //绘制一个遮罩
    //贝塞尔曲线 画一个带有圆角的矩形
    UIBezierPath *bpath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height) cornerRadius:0];
    //贝塞尔曲线 画一个矩形
    [bpath appendPath:[[UIBezierPath bezierPathWithRoundedRect:CGRectMake(self.frame.size.width/2-235/2, self.frame.size.height/2 - 394/2, 249,394) cornerRadius:0] bezierPathByReversingPath]];
    
    
    CAShapeLayer *shapeLayer = [CAShapeLayer layer];
    shapeLayer.path = bpath.CGPath;
    
    //添加图层蒙板
    self.mView.layer.mask = shapeLayer;
    
    UIColor *color = kLineColor;
    [color set]; //设置线条颜色
    UIBezierPath *path = [UIBezierPath bezierPath];
    
    //左上角
    [path moveToPoint:CGPointMake(20 + 5/2, 10 + 26 + 5/2)];
    [path addLineToPoint:CGPointMake(20 + 5/2, 10 + 5/2)];
    [path addLineToPoint:CGPointMake(10 + 26 + 5/2, 10 + 5/2)];
    path.lineWidth = 5;
    
    //左下角
    [path moveToPoint:CGPointMake(20 + 5/2, CGRectGetHeight(self.frame) - 10 - 26)];
    [path addLineToPoint:CGPointMake(20 + 5/2, CGRectGetHeight(self.frame) - 10 - 5/2)];
    [path addLineToPoint:CGPointMake(20 + 26 + 5/2, CGRectGetHeight(self.frame) - 10 - 5/2)];
    path.lineWidth = 5;
    
    //右上角
    [path moveToPoint:CGPointMake(CGRectGetWidth(self.frame) - 20 - 26 - 5/2, 10 + 5/2)];
    [path addLineToPoint:CGPointMake(CGRectGetWidth(self.frame) - 20 - 5/2, 10 + 5/2)];
    [path addLineToPoint:CGPointMake(CGRectGetWidth(self.frame) - 20 - 5/2, 10 + 26 + 5/2)];
    path.lineWidth = 5;
    
    //右下角
    [path moveToPoint:CGPointMake(CGRectGetWidth(self.frame) - 20 - 26 - 5/2, CGRectGetHeight(self.frame) - 10 - 5/2)];
    [path addLineToPoint:CGPointMake(CGRectGetWidth(self.frame) - 20 - 5/2, CGRectGetHeight(self.frame) - 10 - 5/2)];
    [path addLineToPoint:CGPointMake(CGRectGetWidth(self.frame) - 20 - 5/2, CGRectGetHeight(self.frame) - 10 - 26)];
    path.lineWidth = 5;
    
    [path stroke];
    
}


- (instancetype)initWithFrame:(CGRect)frame {
    
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = [UIColor clearColor];
        //遮罩View
        self.mView = [[UIView alloc] initWithFrame:self.bounds];
        self.mView.backgroundColor = [UIColor blackColor];
        self.mView.alpha = 0.5;
        [self addSubview:self.mView];
        
        //印章
        self.sealView = [[UIView alloc] initWithFrame:CGRectMake(37 + 20, 10 + 10, 115*kScaleX, 117*kScaleY)];
        self.sealView.layer.borderColor = kLineColor.CGColor;
        self.sealView.layer.borderWidth = 2.;
        //照片
        self.photoView = [[UIView alloc] initWithFrame:CGRectMake(10 + 20, CGRectGetHeight(self.frame) - 10 - 10 - 123*kScaleY, 168*kScaleX, 123*kScaleY)];
        self.photoView.layer.borderColor = kLineColor.CGColor;
        self.photoView.layer.borderWidth = 2.;
        
        //标题
        self.titileView = [[UIView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.frame) - 20 - 20 - 42*kScaleY, 0, 45*kScaleY, 300*kScaleX)];
        self.titileView.yl_midY = self.yl_midY;
        self.titileView.layer.borderColor = kLineColor.CGColor;
        self.titileView.layer.borderWidth = 2.;
        
        //提示
        self.tipLabel = [[UILabel alloc] init];
        
        [self addSubview:self.tipLabel];
        [self.tipLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.mView);
            make.right.equalTo(self).offset(0);
        }];
        self.tipLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:19*kScaleY];
        self.tipLabel.textColor = [UIColor whiteColor];
        self.tipLabel.transform = CGAffineTransformRotate(self.tipLabel.transform, M_PI_2);
//        self.tipLabel.text = @"身份证正面照";
        
    }
    
    return self;
}

//- (void)setCameraType:(ScoreCameraType)cameraType {
//    _cameraType = cameraType;
//    
//    switch (cameraType) {
//        case ScoreCameraTypeIDCardFront://身份证正面
//            self.tipLabel.text = @"身份证正面";
//            break;
//        case ScoreCameraTypeIDCardBack://身份证背面
//           self.tipLabel.text = @"身份证背面";
//            break;
//        case ScoreCameraTypeDrivingFront:
//            self.tipLabel.text = @"驾驶证正面";
//            break;
//        case ScoreCameraTypeDrivingBack://行驶证正面
//            self.tipLabel.text = @"驾驶证背面";
//            break;
//        case ScoreCameraTypeTravelFront://行驶证正面
//            self.tipLabel.text = @"行驶证正面";
//            break;
//        case ScoreCameraTypeTravelBack://行驶证正面
//            self.tipLabel.text = @"行驶证背面";
//            break;
//        case ScoreCameraTypeCertificateFront:
//            self.tipLabel.text = @"从业资格证正面";
//            break;
//        case ScoreCameraTypeCertificateBack:
//            self.tipLabel.text = @"从业资格证反面";
//            break;
//        case ScoreCameraTypeTransportFront:
//            self.tipLabel.text = @"道路运输证正面";
//            break;
//        case ScoreCameraTypeTransportBack:
//            self.tipLabel.text = @"道路运输证反面";
//            break;
//        case ScoreCameraTypeLiability:
//            self.tipLabel.text = @"身份证背面";
//            break;
//        default:
//            break;
//    }
//}


@end
